<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Models\Traits\SearchHandler;



class User extends Authenticatable
{
    use Notifiable,SearchHandler;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','account','weixin_openid','weixin_unionid','avatar'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    // 客户套餐等级 表
    public function package(){

        return $this->belongsTo(Package::class , 'package_id' , 'id');
    }


    // 用户信息 表
    public function user_info(){

        return $this->belongsTo(UserInfo::class , 'id' , 'user_id');
    }


    // 客户商品 表
    public function goods(){

        return $this->hasMany(Goods::class);
    }


    /* 客户 分销店铺表  多对多模型关联
     * 第一个参数：要关联的表对应的类
     * 第二个参数：中间表的表名
     * 第三个参数：当前表跟中间表对应的外键
     * 第四个参数：要关联的表跟中间表对应的外键
     * */
    public function shop(){

        return $this->belongsToMany(Shop::class , 'user_to_shops' , 'user_id' , 'shop_id');
    }

    // 浏览模型关联
    public function goods_browse(){

        return $this->hasMany(GoodsBrowse::class);
    }


    // 当天浏览总计表关联
    public function userBrowseTotal(){

        return $this->hasMany(UserBrowseTotal::class , 'user_id' , 'id');
    }


}
